package com.zking.filter;

import com.zking.dao.CategoryDao;
import com.zking.entity.Category;

import javax.servlet.*;
import javax.servlet.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;

public class ClassFilter implements Filter {
    public void init(FilterConfig config) throws ServletException {
    }

    public void destroy() {
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {

        HttpServletRequest httpServletRequest = (HttpServletRequest) request;

        List<Category> list = CategoryDao.getBigCategory();
        list.sort(((o1, o2) -> o1.getEpc_id()-o2.getEpc_id()));

        httpServletRequest.setAttribute("classList", list);

        chain.doFilter(request, response);
    }
}
